package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description 预约列表控制类
 * @Author makun
 * @Date 2023/9/23 14:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @DeleteMapping
    public Result deleteById(Integer id) {
        return orderService.delete(id) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 将预约状态改为已到诊
     * @param map
     * @return
     */
    @PutMapping("/visit")
    public Result visit(@RequestBody Map<String, Object> map) {
        return orderService.hasVisit((Integer) map.get("id")) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 分页查询预约列表
     * @param queryPageBean
     * @return
     */
    @GetMapping
    public Result getOrders(QueryPageBean queryPageBean) {
        return Result.buildSuccess(orderService.findPage(queryPageBean));
    }
}
